<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.16"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>LibTools: H:/project/LibTools/src/thread/Mutex.cpp 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">LibTools
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.16 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','搜索');
});
/* @license-end */</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_bfedb72b9d87795234454f6223b9ab1e.html">thread</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Mutex.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_mutex_8cpp.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#include &lt;exception&gt;</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#include &lt;stdexcept&gt;</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_mutex_8h.html">Mutex.h</a>&quot;</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160; </div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<a class="code" href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160; </div>
<div class="line"><a name="l00007"></a><span class="lineno"><a class="line" href="_mutex_8cpp.html#a40c138689f2c842e1bb381b15e8d42ae">    7</a></span>&#160;<span class="preprocessor">#define THROW_MUTEX throw std::invalid_argument(&quot;mutex is NULL&quot;)</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160; </div>
<div class="line"><a name="l00009"></a><span class="lineno"><a class="line" href="class_c_mutex.html#a9c050f1451600e8bc35c4c80f6533800">    9</a></span>&#160;<a class="code" href="class_c_mutex.html#a9c050f1451600e8bc35c4c80f6533800">CMutex::CMutex</a>()</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;{</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;     <a class="code" href="class_c_mutex.html#aed1ca9921a072b197627c7ccbcf5bfb5">_mutex</a> = <a class="code" href="namespace_share_api.html#a1a12fe17284d65b76175e2ea80279f9e">ShareApi::CreateMutex</a>();</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;}</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160; </div>
<div class="line"><a name="l00014"></a><span class="lineno"><a class="line" href="class_c_mutex.html#a43fa2c418e6ec1ede656c8b9c4767494">   14</a></span>&#160;<a class="code" href="class_c_mutex.html#a43fa2c418e6ec1ede656c8b9c4767494">CMutex::~CMutex</a>()</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;{</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;    <span class="keywordflow">if</span> (<a class="code" href="class_c_mutex.html#aed1ca9921a072b197627c7ccbcf5bfb5">_mutex</a>)</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;    {</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;        <a class="code" href="namespace_share_api.html#a8f77f0ed93c1add64d17085612759c2e">ShareApi::CloseMutex</a>(<a class="code" href="class_c_mutex.html#aed1ca9921a072b197627c7ccbcf5bfb5">_mutex</a>);</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;         <a class="code" href="class_c_mutex.html#aed1ca9921a072b197627c7ccbcf5bfb5">_mutex</a> = 0;</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;    }</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;}</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160; </div>
<div class="line"><a name="l00023"></a><span class="lineno"><a class="line" href="class_c_mutex.html#af673eb768848738ed476d4ce2e2eb443">   23</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_c_mutex.html#af673eb768848738ed476d4ce2e2eb443">CMutex::Lock</a>()</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;{</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;    <span class="keywordflow">if</span> (!<a class="code" href="class_c_mutex.html#aed1ca9921a072b197627c7ccbcf5bfb5">_mutex</a>) <a class="code" href="_mutex_8cpp.html#a40c138689f2c842e1bb381b15e8d42ae">THROW_MUTEX</a>;</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;    <a class="code" href="namespace_share_api.html#a87b8d6d01e677432b988eef8ce62c3fb">ShareApi::MutexLock</a>(<a class="code" href="class_c_mutex.html#aed1ca9921a072b197627c7ccbcf5bfb5">_mutex</a>);</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;}</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160; </div>
<div class="line"><a name="l00029"></a><span class="lineno"><a class="line" href="class_c_mutex.html#ac0a6922590d43c88d9343feac2ccba2c">   29</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_c_mutex.html#ac0a6922590d43c88d9343feac2ccba2c">CMutex::Unlock</a>()</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;{</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    <span class="keywordflow">if</span> (!<a class="code" href="class_c_mutex.html#aed1ca9921a072b197627c7ccbcf5bfb5">_mutex</a>) <a class="code" href="_mutex_8cpp.html#a40c138689f2c842e1bb381b15e8d42ae">THROW_MUTEX</a>;</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;    <a class="code" href="namespace_share_api.html#ae5ba1f54275e01ae695344690c8e5f40">ShareApi::MutexUnlock</a>(<a class="code" href="class_c_mutex.html#aed1ca9921a072b197627c7ccbcf5bfb5">_mutex</a>);</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;}</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160; </div>
<div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="class_c_mutex.html#aef8094fb14fbccf8e095b162ba90dade">   35</a></span>&#160;<a class="code" href="tools_8h.html#a01e895c2df346ffe662bbe69686d8d51">SYNCHANDLE</a> <a class="code" href="class_c_mutex.html#aef8094fb14fbccf8e095b162ba90dade">CMutex::Handle</a>()</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;{</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="class_c_mutex.html#aed1ca9921a072b197627c7ccbcf5bfb5">_mutex</a>;</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;}</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160; </div>
<div class="line"><a name="l00040"></a><span class="lineno"><a class="line" href="class_c_lock_gurad.html#ac136696fa57b06112d574d314decdfec">   40</a></span>&#160;<a class="code" href="class_c_lock_gurad.html#ac136696fa57b06112d574d314decdfec">CLockGurad::CLockGurad</a>(<a class="code" href="class_c_mutex_base.html">CMutexBase</a> *pBase)</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;{</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;     <a class="code" href="class_c_lock_gurad.html#abd68b7223e2d85cb91b5108f5eaafd15">_mutex</a> = pBase;</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;    <a class="code" href="class_c_lock_gurad.html#a27f8943da04cefd1d078ad9348279f8c">Lock</a>();</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;}</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160; </div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160; </div>
<div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="class_c_lock_gurad.html#a2aef4e31312c9870ba4b0aa490b8651d">   47</a></span>&#160;<a class="code" href="class_c_lock_gurad.html#a2aef4e31312c9870ba4b0aa490b8651d">CLockGurad::~CLockGurad</a>()</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;{</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    <a class="code" href="class_c_lock_gurad.html#af36a84e9f639bc96d17c5cc725c62da1">Unlock</a>();</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;}</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160; </div>
<div class="line"><a name="l00052"></a><span class="lineno"><a class="line" href="class_c_lock_gurad.html#a27f8943da04cefd1d078ad9348279f8c">   52</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_c_lock_gurad.html#a27f8943da04cefd1d078ad9348279f8c">CLockGurad::Lock</a>()</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;{</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;     <a class="code" href="class_c_lock_gurad.html#abd68b7223e2d85cb91b5108f5eaafd15">_mutex</a>-&gt;<a class="code" href="class_c_mutex_base.html#ac23d438cd5b38643a222bcb74adbb604">Lock</a>();</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;}</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160; </div>
<div class="line"><a name="l00057"></a><span class="lineno"><a class="line" href="class_c_lock_gurad.html#af36a84e9f639bc96d17c5cc725c62da1">   57</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_c_lock_gurad.html#af36a84e9f639bc96d17c5cc725c62da1">CLockGurad::Unlock</a>()</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;{</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;     <a class="code" href="class_c_lock_gurad.html#abd68b7223e2d85cb91b5108f5eaafd15">_mutex</a>-&gt;<a class="code" href="class_c_mutex_base.html#abd6a9da2d294b50fc9651c1be6b7e808">Unlock</a>();</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;}</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160; </div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;<a class="code" href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="aclass_c_lock_gurad_html_a2aef4e31312c9870ba4b0aa490b8651d"><div class="ttname"><a href="class_c_lock_gurad.html#a2aef4e31312c9870ba4b0aa490b8651d">CLockGurad::~CLockGurad</a></div><div class="ttdeci">~CLockGurad()</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00047">Mutex.cpp:47</a></div></div>
<div class="ttc" id="anamespace_share_api_html_a1a12fe17284d65b76175e2ea80279f9e"><div class="ttname"><a href="namespace_share_api.html#a1a12fe17284d65b76175e2ea80279f9e">ShareApi::CreateMutex</a></div><div class="ttdeci">LIBTOOLS SYNCHANDLE CreateMutex()</div><div class="ttdoc">创建锁</div><div class="ttdef"><b>Definition:</b> <a href="_share_api_8cpp_source.html#l01210">ShareApi.cpp:1210</a></div></div>
<div class="ttc" id="aclass_c_lock_gurad_html_abd68b7223e2d85cb91b5108f5eaafd15"><div class="ttname"><a href="class_c_lock_gurad.html#abd68b7223e2d85cb91b5108f5eaafd15">CLockGurad::_mutex</a></div><div class="ttdeci">CMutexBase * _mutex</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8h_source.html#l00050">Mutex.h:50</a></div></div>
<div class="ttc" id="aclass_c_mutex_html_a43fa2c418e6ec1ede656c8b9c4767494"><div class="ttname"><a href="class_c_mutex.html#a43fa2c418e6ec1ede656c8b9c4767494">CMutex::~CMutex</a></div><div class="ttdeci">virtual ~CMutex()</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00014">Mutex.cpp:14</a></div></div>
<div class="ttc" id="aclass_c_mutex_base_html"><div class="ttname"><a href="class_c_mutex_base.html">CMutexBase</a></div><div class="ttdoc">锁基类</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8h_source.html#l00011">Mutex.h:11</a></div></div>
<div class="ttc" id="aclass_c_lock_gurad_html_af36a84e9f639bc96d17c5cc725c62da1"><div class="ttname"><a href="class_c_lock_gurad.html#af36a84e9f639bc96d17c5cc725c62da1">CLockGurad::Unlock</a></div><div class="ttdeci">void Unlock()</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00057">Mutex.cpp:57</a></div></div>
<div class="ttc" id="aclass_c_lock_gurad_html_a27f8943da04cefd1d078ad9348279f8c"><div class="ttname"><a href="class_c_lock_gurad.html#a27f8943da04cefd1d078ad9348279f8c">CLockGurad::Lock</a></div><div class="ttdeci">void Lock()</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00052">Mutex.cpp:52</a></div></div>
<div class="ttc" id="atools_8h_html_a201ce692c9dca6599e5c12d00167419b"><div class="ttname"><a href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div><div class="ttdeci">#define DEF_BEG_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00036">tools.h:36</a></div></div>
<div class="ttc" id="aclass_c_mutex_html_aed1ca9921a072b197627c7ccbcf5bfb5"><div class="ttname"><a href="class_c_mutex.html#aed1ca9921a072b197627c7ccbcf5bfb5">CMutex::_mutex</a></div><div class="ttdeci">SYNCHANDLE _mutex</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8h_source.html#l00035">Mutex.h:35</a></div></div>
<div class="ttc" id="anamespace_share_api_html_a8f77f0ed93c1add64d17085612759c2e"><div class="ttname"><a href="namespace_share_api.html#a8f77f0ed93c1add64d17085612759c2e">ShareApi::CloseMutex</a></div><div class="ttdeci">LIBTOOLS void CloseMutex(SYNCHANDLE hMutex)</div><div class="ttdoc">销毁锁</div><div class="ttdef"><b>Definition:</b> <a href="_share_api_8cpp_source.html#l01247">ShareApi.cpp:1247</a></div></div>
<div class="ttc" id="a_mutex_8h_html"><div class="ttname"><a href="_mutex_8h.html">Mutex.h</a></div></div>
<div class="ttc" id="atools_8h_html_ac909db71799bb22cb7d636a34cd785e4"><div class="ttname"><a href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div><div class="ttdeci">#define DEF_END_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00038">tools.h:38</a></div></div>
<div class="ttc" id="aclass_c_lock_gurad_html_ac136696fa57b06112d574d314decdfec"><div class="ttname"><a href="class_c_lock_gurad.html#ac136696fa57b06112d574d314decdfec">CLockGurad::CLockGurad</a></div><div class="ttdeci">CLockGurad(CMutexBase *mutex)</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00040">Mutex.cpp:40</a></div></div>
<div class="ttc" id="aclass_c_mutex_html_ac0a6922590d43c88d9343feac2ccba2c"><div class="ttname"><a href="class_c_mutex.html#ac0a6922590d43c88d9343feac2ccba2c">CMutex::Unlock</a></div><div class="ttdeci">virtual void Unlock()</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00029">Mutex.cpp:29</a></div></div>
<div class="ttc" id="aclass_c_mutex_html_af673eb768848738ed476d4ce2e2eb443"><div class="ttname"><a href="class_c_mutex.html#af673eb768848738ed476d4ce2e2eb443">CMutex::Lock</a></div><div class="ttdeci">virtual void Lock()</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00023">Mutex.cpp:23</a></div></div>
<div class="ttc" id="aclass_c_mutex_html_aef8094fb14fbccf8e095b162ba90dade"><div class="ttname"><a href="class_c_mutex.html#aef8094fb14fbccf8e095b162ba90dade">CMutex::Handle</a></div><div class="ttdeci">virtual SYNCHANDLE Handle()</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00035">Mutex.cpp:35</a></div></div>
<div class="ttc" id="a_mutex_8cpp_html_a40c138689f2c842e1bb381b15e8d42ae"><div class="ttname"><a href="_mutex_8cpp.html#a40c138689f2c842e1bb381b15e8d42ae">THROW_MUTEX</a></div><div class="ttdeci">#define THROW_MUTEX</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00007">Mutex.cpp:7</a></div></div>
<div class="ttc" id="anamespace_share_api_html_a87b8d6d01e677432b988eef8ce62c3fb"><div class="ttname"><a href="namespace_share_api.html#a87b8d6d01e677432b988eef8ce62c3fb">ShareApi::MutexLock</a></div><div class="ttdeci">LIBTOOLS void MutexLock(SYNCHANDLE hMutex)</div><div class="ttdoc">加锁</div><div class="ttdef"><b>Definition:</b> <a href="_share_api_8cpp_source.html#l01229">ShareApi.cpp:1229</a></div></div>
<div class="ttc" id="anamespace_share_api_html_ae5ba1f54275e01ae695344690c8e5f40"><div class="ttname"><a href="namespace_share_api.html#ae5ba1f54275e01ae695344690c8e5f40">ShareApi::MutexUnlock</a></div><div class="ttdeci">LIBTOOLS void MutexUnlock(SYNCHANDLE hMutex)</div><div class="ttdoc">解锁</div><div class="ttdef"><b>Definition:</b> <a href="_share_api_8cpp_source.html#l01238">ShareApi.cpp:1238</a></div></div>
<div class="ttc" id="atools_8h_html_a01e895c2df346ffe662bbe69686d8d51"><div class="ttname"><a href="tools_8h.html#a01e895c2df346ffe662bbe69686d8d51">SYNCHANDLE</a></div><div class="ttdeci">#define SYNCHANDLE</div><div class="ttdoc">异步函数句柄</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00329">tools.h:329</a></div></div>
<div class="ttc" id="aclass_c_mutex_base_html_ac23d438cd5b38643a222bcb74adbb604"><div class="ttname"><a href="class_c_mutex_base.html#ac23d438cd5b38643a222bcb74adbb604">CMutexBase::Lock</a></div><div class="ttdeci">virtual void Lock()=0</div></div>
<div class="ttc" id="aclass_c_mutex_base_html_abd6a9da2d294b50fc9651c1be6b7e808"><div class="ttname"><a href="class_c_mutex_base.html#abd6a9da2d294b50fc9651c1be6b7e808">CMutexBase::Unlock</a></div><div class="ttdeci">virtual void Unlock()=0</div></div>
<div class="ttc" id="aclass_c_mutex_html_a9c050f1451600e8bc35c4c80f6533800"><div class="ttname"><a href="class_c_mutex.html#a9c050f1451600e8bc35c4c80f6533800">CMutex::CMutex</a></div><div class="ttdeci">CMutex()</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00009">Mutex.cpp:9</a></div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.16
</small></address>
</body>
</html>
